fjNetwork.get('visit/statistic/add.json','',function(data){
	console.log(JSON.stringify(data));
},function(msg){
	console.log(msg);
});


    var swiper = new Swiper('.swiper-container-tag', {
        pagination: '.swiper-pagination',
        slidesPerView: 'auto',
        paginationClickable: true,
        freeMode: true
    });
    
			mui.plusReady(function() {
				var areaUtil = areaUtils;
				areaUtil.setNetworkClient(fjNetwork);
				//获取城市列表
				var areaLevelCity = 2;
				
				areaUtil.getAreaListByLevel(areaLevelCity,function(){
					
					var currentCity = areaUtil.getCurrentCity();

					if(currentCity==null){
						areaUtil.setCurrentCityByCityName('泉州市');
					}
					
				});		

				
				
				
				
				openWebviewFromOthers();
				//当子页面的内容完全加载完毕后，再展示
				var currentView = plus.webview.currentWebview();
				currentView.show('slide-in-right', 300);
				plus.nativeUI.closeWaiting();

				//搜索框
				document.querySelector('#openSearchPage').addEventListener('tap', function() {
					mui.openWindow({
						url: 'fj_search.html',
						extras: {
							parentName: 'indexPage'
						}
					})
				});
				//资讯滚动
				var informationParam = [{
					key: 'page',
					value: 1
				}, {
					key: 'rows',
					value: 20
				}];
				fjNetwork.get('fjzx/common/text-ad-list.json', informationParam, function(data) {
					var infomationRows = data.rows;
					$('#infomationTmpl').tmpl(infomationRows).appendTo('#infomation');

					$(".txtScroll-top").slide({
						mainCell: "ul",
						effect: "topLoop",
						autoPlay: true
					});

					mui('#infomation').on('tap', 'li', function(event) {
						event.preventDefault();
					});
				})


				getTradeProgressData(fjNetwork);

				//广告轮播图 
				fjNetwork.get('fjzx/client/index-ad.json', '', function(data) {
					var adList = data.adList;
					var adListGroup = document.querySelector('#adListGroup');
					var adListIndicator = document.querySelector('#adListIndicator');
					var sliderArr = new Array();
					var adListIndicatorArr = new Array();
					sliderArr.push('<div class="mui-slider-item mui-slider-item-duplicate">');
					sliderArr.push('<a>');
					sliderArr.push('<img src="' + adList[adList.length - 1].imgFullUrl + '"/>');
					sliderArr.push('</a>');
					sliderArr.push('</div>');
					for(idx in adList) {
						sliderArr.push('<div class="mui-slider-item">');
						sliderArr.push('<a>');
						sliderArr.push('<img src="' + adList[idx].imgFullUrl + '" />');
						sliderArr.push('</a>');
						sliderArr.push('</div>');
						adListIndicatorArr.push('<div class="mui-indicator"></div>');
					}
					sliderArr.push('<div class="mui-slider-item mui-slider-item-duplicate">');
					sliderArr.push('<a href="#">');
					sliderArr.push('<img src="' + adList[0].imgFullUrl + '" />');
					sliderArr.push('</a>');
					sliderArr.push('</div>');
					adListGroup.innerHTML = sliderArr.join('');
					document.querySelector('#banner1').classList.add('mui-hidden');
					adListIndicator.innerHTML = adListIndicatorArr.join('');
					adListIndicator.getElementsByTagName('div')[0].classList.add('mui-active');

					//获得slider插件对象
					var gallery = mui('#slider');
					gallery.slider({
						interval: 3000 //自动轮播周期，若为0则不自动播放，默认为0；
					});
					/*获取Windows的宽度
					 * 然后按比例设置slide的图片高度 	比例9:21=3:7
					 */
					var winW = window.screen.width;
					var slideImg = $('#adListGroup img');
					for(i in slideImg) {
						slideImg.eq(i).height(winW / 7 * 3);
					}
					document.querySelector('#banner1').height = winW / 7 * 3;
				}, function(msg) {
					mui.toast(msg);
				});

				//房屋列表 
				var recommendParam = [{
					key: 'page',
					value: 1
				}, {
					key: 'rows',
					value: 10
				}];
				fjNetwork.get('fjzx/client/house-recommend-list.json', recommendParam, function(data) {
					var recommendRows = data.rows;
					$('#recommendHouseTmpl').tmpl(recommendRows, {
						getKeyword: function() {
							var keyword = this.data.keyword;
							if(keyword) {
								var keywordArr = keyword.split(',');
								var keywordCls = [
									'keyword-color1 ',
									'keyword-color2 ',
									'keyword-color3 ',
									'keyword-color4 '
								];
								var len = keywordArr.length<4?keywordArr.length:4
								var keywordData = new Array();
								for(var i = 0; i < len; i++) {
									var pas = i % keywordCls.length;
									keywordData[i] = {
										className: keywordCls[pas],
										value: keywordArr[i]
									};
								}
								return keywordData;
							} else {
								return keyword = '';
							}
						}
					}).appendTo('#recommendHouse');
					var imgObj = $('#recommendHouse img');
					var RATE = 0.75;	//常量，图片框比例
					imgObj.each(function(){
						$(this).load(function(){
							var rate = parseFloat($(this).height()/$(this).width());
							if(rate<RATE){		//高度不够
								$(this).css('height','75px');
								$(this).css('width',$(this).height()/rate);
							}else{				//宽度不够
								$(this).css('width','100px');
								$(this).css('height',$(this).width()*rate);
							}
							if($(this).width()>100){
								var marginLeft = parseInt(-($(this).width()-100)*0.5);
								$(this).css('margin-left',marginLeft);
							}
							if($(this).height()>75){
								var marginTop = parseInt(-($(this).height()-75)*0.5);
								$(this).css('margin-top',marginTop);
							}
						});
					});
				}, function(msg) {
					mui.toast(msg);
				});
				mui('#recommendHouse').on('tap', 'li', function() {
					mui.openWindow({
						url: 'house_detail.html',
						id: 'house_detail',
						extras: {
							houseId: this.getAttribute('id')
						}
					})
				});
				//更多推荐
				document.querySelector('#moreRecommend').addEventListener('tap', function() {
					openWindowWithPage('fj_recommend');
				});
				//默认显示当前城市
				var currentCity = areaUtils.getCurrentCity();
//				console.log(JSON.stringify(currentCity));
				if(currentCity==null){
					var paramaArea = [{
						key: 'grade',
						value: 2
					}];
					//获取地区列表
					fjNetwork.get('/area/areaList.json', paramaArea, function(data) {
						
						//成功
						var cityList = data.areaList;
						currentCity = new Object;
						for(var i = 0; i < cityList.length; i++) {
							var tempCity = cityList[i];
							if(tempCity.areaName.indexOf('泉州市') >= 0) {
								currentCity = tempCity;
								break;
							}
						}
						document.querySelector('#currentCity').innerHTML = currentCity.areaName;
			
					}, function(message) {
						//失败
					});
					
				}else{
					document.querySelector('#currentCity').innerHTML = currentCity.areaName;
				}
				
				document.addEventListener('getchildCity', function(event) {
					cityArea = event.detail.cityName;
					cityAreaIdentId = event.detail.cityAreaIdentId;
					document.querySelector('#currentCity').innerHTML = cityArea;
				});
				document.querySelector('#currentCity').addEventListener('tap', function() {
					mui.openWindow({
						url: 'fj_child_cities.html',
						extras: {
							parentId: 'xol_index',
							identId: currentCity.identId,
							currentCity: currentCity.areaName
						}
					})
				});
				//二手房
				mui('.secondHandHouse').each(function(){
					this.addEventListener('tap',function(){
						openWindowWithPage('secondhand_house');
					});
				});
				//新房
				document.querySelector('#newHouse').addEventListener('tap', function() {
					openWindowWithPage('new_house');
				});
				
				//普通租房
				document.querySelector('#sellHouse').addEventListener('tap', function() {
					openWindowWithPage('fj_house_list');

				});
				//租房
				mui('.rentHouse').each(function(){
					this.addEventListener('tap',function(){
						openWindowWithPage('fj_house_list');
					});
				});
				// 工装
				document.querySelector('#gongzhuang').addEventListener('tap',function(){
					openFileWindowWithPage('company','newMenu_list',{
						type:1
					});
				});
				
				// 家装
//				document.querySelector('#jiazhuang').addEventListener('tap',function(){
//					openFileWindowWithPage('company','newMenu_list',{
//						type:2
//					});
//				});
				mui('.jiazhuang').each(function(){
					this.addEventListener('tap',function(){
						openFileWindowWithPage('company','newMenu_list',{
							type:2
						});
					});
				});
				
				// 家政
				document.querySelector('#starServe').addEventListener('tap',function(){
					openFileWindowWithPage('company','newMenu_list',{
						type:3
					});
				});
				document.querySelector('#aiClean').addEventListener('tap',function(){
					openFileWindowWithPage('company','companyDetail',{
						type:3,
						shopId:6
					});
				});
				
				//生活
//				mui('.gotoList-life').each(function(){
//					this.addEventListener('tap',function(){
//						openFileWindowWithPage('company','newMenu_list',{
//							type:4
//						});
//					});
//				});
//				mui('.gotoList-jiazhuang').each(function(){
//					this.addEventListener('tap',function(){
//						mui.toast('敬请期待');
//					});
//				});
				//生活-有钱
				document.querySelector('#food').addEventListener('tap',function(){
					openFileWindowWithPage('company','newMenu_list',{
						type:6
					});
				});
				//生活-便民
//				document.querySelector('#bianmin').addEventListener('tap',function(){
//					openFileWindowWithPage('company','newMenu_list',{
//						type:5
//					});
//				});
				mui('.bianmin').each(function(){
					this.addEventListener('tap',function(){
						openFileWindowWithPage('company','newMenu_list',{
							type:4
						});
					});
				});
				
				updateUserPushIdentifier();
				var net = fjNetwork;
				getBaseData(net);
				getTradeProgressData(net);
				var userInfo = common.myStorage.getItem('userInfo');
				//				document.querySelector('#txtUsername').value = userInfo.realname;

				document.addEventListener("newintent", function() {
					openWebviewFromOthers();
				});
				plus.push.addEventListener("receive", function(msg) {
					//获取透传数据
					//创建本地消息
					createLocalPushMsg(msg.payload);
				}, false);

			}); //mui.plusReady()end

			var updateUserPushIdentifier = function() {
				var info = plus.push.getClientInfo();
				//				console.log("获取客户端推送标识信息：");
				//				console.log("token: " + info.token);
				//				console.log("clientid: " + info.clientid);
				//				console.log("appid: " + info.appid);
				//				console.log("appkey: " + info.appkey);
				if(info.token.length > 0 && info.clientid.length > 0) {
					var userInfo = common.myStorage.getItem('userInfo');
					if(userInfo) {
						var param = [{
							key: 'userId',
							value: userInfo.id
						}, {
							key: 'alias',
							value: userInfo.mobile
						}, {
							key: 'clientId',
							value: info.clientid
						}, {
							key: 'deviceToken',
							value: info.token
						}];
						var net = fjNetwork;
						net.post('user/updateAppUser.json', param, function(data) {
							//成功
						}, function(message) {
							//失败
						});
					}

				}
			};
			//创建本地推送
			function createLocalPushMsg(pushPlayload) {
				mui.alert(pushPlayload);
				var options = {
					cover: false,
				};
				var content = '收到一条新消息';
				if(pushPlayload == 'DISPATCH_SALEMAN') {
					content = '您的预约看房行程已确认，我们为您安排了一位专属经纪人';
				} else if(pushPlayload == 'HOUSE_TRADING_STATE_CHANGE') {
					content = '您的房源有新的交易进展';
				}
				//				else if(pushPlayload == 'CANCEL_RESERVE_HOUSE') {
				//					content = '有客户取消了看房预约';
				//				} else if(pushPlayload == 'HOUSE_TRADING_STATE_CHANGE') {
				//					content = '收到一条新客户评价';
				//				} else if(pushPlayload == 'ADD_COMMENT') {
				//					content = '房源有新的交易进展';
				//				}
				plus.push.createMessage(content, pushPlayload, options);
			}
			//从地址获取查询参数
			function GetQueryString(url, name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var strSearch = url.substring(url.indexOf('?'));
				var r = strSearch.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			}
			//获取通知栏（app未启动）点击、第三方程序启动本app
			function openWebviewFromOthers() {
				var args = plus.runtime.arguments;

				if(args) {
					if(args.indexOf('xinzaixian://houseDetail') >= 0) {
						//schemes url
						var houseId = GetQueryString(args, 'houseId');
						var kind = GetQueryString(args, 'kind');
						if(houseId==0){
							
						}else{
							mui.openWindow({
								url: 'house_detail.html',
								id: 'house_detail',
								extras: {
									houseId: houseId,
									kind: kind
								}
							})
						}
						
					}else if(args.indexOf('xinzaixian://buildingDetail') >= 0) {
						//schemes url
						var buildingId = GetQueryString(args, 'buildingId');
						if(buildingId==0){
							
						}else{
							mui.openWindow({
								url: 'house_detail.html',
								id: 'house_detail',
								extras: {
									houseId: houseId,
									kind: kind
								}
							})
						}
						
					}else if(args.indexOf('xinzaixian://shopDetail') >= 0) {
						//schemes url
						var shopId = GetQueryString(args, 'shopId');
						var type = GetQueryString(args, 'type');
						if(shopId==0){
							
						}else{
							mui.openWindow({
								url: 'company/companyDetail.html',
								id: 'companyDetail',
								extras: {
									shopId: shopId,
									type: type
								}
							})
						}
						
					}else {
						var pushPlayload = args;
						var content = '收到一条新消息';
						if(pushPlayload == 'DISPATCH_SALEMAN') {
							content = '系统已为你安排预约客户，请到“我的预约”中查看';
						} else if(pushPlayload == 'HOUSE_TRADING_STATE_CHANGE') {
							content = '房源有新的交易进展，请到“交易进度”中查看';
						}
						//					else if(pushPlayload == 'CANCEL_RESERVE_NEW_BUILDING') {
						//						content = '有客户取消了新楼盘的看房预约，请到“我的预约”中查看';
						//					} else if(pushPlayload == 'CANCEL_RESERVE_HOUSE') {
						//						content = '有客户取消了看房预约，请到“我的预约”中查看';
						//					} else if(pushPlayload == 'ADD_COMMENT') {
						//						content = '房源有新的交易进展，请到“我的服务”中查看';
						//					}
						mui.alert(content, '收到新消息', '知道了', function(e) {
							e.index;
							if(pushPlayload == 'DISPATCH_SALEMAN') {
								openFileWindowWithPage('personal_pages', 'xol_reservation'); //我的预约
							} else if(pushPlayload == 'HOUSE_TRADING_STATE_CHANGE') {
								openFileWindowWithPage('personal_pages', 'xol_entrust'); //交易进度
							}
						}, 'div');
					}

				}
			};